package com.tj.admin.auth.response;

import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.common.utils.StringUtils;
import com.jsoniter.JsonIterator;
import com.jsoniter.any.Any;
import com.qianli.cashmama.product.facade.result.ProductCategory;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2021/11/10
 * Time: 11:28 上午
 */
public class ProductListResponse implements Serializable {

    private static final long serialVersionUID = -5541725864725732951L;

    private List<Item> list = new ArrayList<>();

    public ProductListResponse() {
    }

    public ProductListResponse(List<ProductCategory> productCategories, Integer forGp) {

        if (!CollectionUtils.isEmpty(productCategories)) {
            productCategories.forEach(productCategory -> {
                if (!productCategory.getForGp().equals(forGp)) {
                    return;
                }
                Item item = new Item();
                item.setLogo(productCategory.getLogo())
                        .setCode(productCategory.getCode())
                        .setName(productCategory.getName())
                        .setSelling(productCategory.getIsSelling())
                        .setDayLimit(productCategory.getDailyApplyLimit());

                //全部 1 新客 2 老客 3 全部 4 停止放款
                Integer lendingUserType = 3;
                String extraInfo = productCategory.getExtraInfo();
                if (!StringUtils.isEmpty(extraInfo)) {
                    Any deserialize = JsonIterator.deserialize(extraInfo);
                    Any lendingUserType1 = deserialize.get("lendingUserType");
                    if (lendingUserType1 != null) {
                        lendingUserType = lendingUserType1.toInt();
                    }

                }

                item.setLendingUserType(lendingUserType);

                list.add(item);
            });
        }

    }

    public List<Item> getList() {
        return list;
    }

    public ProductListResponse setList(List<Item> list) {
        this.list = list;
        return this;
    }

    private class Item {
        private String logo;
        private String code;
        private String name;
        private Integer selling;

        //全部 1 新客 2 老客 3 全部 4 停止放款
        private Integer lendingUserType;


        private Integer dayLimit;


        public String getCode() {
            return code;
        }

        public Item setCode(String code) {
            this.code = code;
            return this;
        }

        public Integer getSelling() {
            return selling;
        }

        public Item setSelling(Integer selling) {
            this.selling = selling;
            return this;
        }

        public String getLogo() {
            return logo;
        }

        public Item setLogo(String logo) {
            this.logo = logo;
            return this;
        }

        public String getName() {
            return name;
        }

        public Item setName(String name) {
            this.name = name;
            return this;
        }

        public Integer getLendingUserType() {
            return lendingUserType;
        }

        public Item setLendingUserType(Integer lendingUserType) {
            this.lendingUserType = lendingUserType;
            return this;
        }

        public Integer getDayLimit() {
            return dayLimit;
        }

        public Item setDayLimit(Integer dayLimit) {
            this.dayLimit = dayLimit;
            return this;
        }
    }
}
